static int nchildren;
static pid_t *pids;
int startup(u_short *port)
{
 int httpd = 0;
 struct sockaddr_in name;
/*建立 socket */
 httpd = socket(PF_INET, SOCK_STREAM, 0);
 if (httpd == -1)
  error_die("socket");
 memset(&name, 0, sizeof(name));
 name.sin_family = AF_INET;
 name.sin_port = htons(*port);
 name.sin_addr.s_addr = htonl(INADDR_ANY);
 if (bind(httpd, (struct sockaddr *)&name, sizeof(name)) < 0)
  error_die("bind");
  /*如果当前指定端口是 0，则动态随机分配一个端口*/
 if (*port == 0)  /* if dynamically allocating a port */
 {
  int namelen = sizeof(name);
  if (getsockname(httpd, (struct sockaddr *)&name, &namelen) == -1)
   error_die("getsockname");
  *port = ntohs(name.sin_port);
 }
 /*开始监听*/
 if (listen(httpd, 5) < 0)
  error_die("listen");
  /*返回 socket id */
 return(httpd);
}

int main(int argc,char *argv)
{
	int listenfd,i;
	socklen_t addrlen;
	void sig_int(int);
	pid_t child_make(int,int,int);
	
	int server_sock = -1;
 	u_short port = 0;
 	int client_sock = -1;
 	struct sockaddr_in client_name;
 	int client_name_len = sizeof(client_name);
 	pthread_t newthread;

 	server_sock = startup(&port);
}
